<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: Unit</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.board</a> ]
    </div>

    <h1>Coverage Summary for Class: Unit (nl.tudelft.jpacman.board)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">Unit</td>
            <td class="coverageStat">
  <span class="percent">
    100%
  </span>
                <span class="absValue">
    (1/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    10%
  </span>
                <span class="absValue">
    (1/ 10)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    3.4%
  </span>
                <span class="absValue">
    (1/ 29)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.board;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
        <i>4</i>&nbsp;
        <i>5</i>&nbsp;/**
        <i>6</i>&nbsp; * A unit that can be placed on a {@link Square}.
        <i>7</i>&nbsp; *
        <i>8</i>&nbsp; * @author Jeroen Roosen
        <i>9</i>&nbsp; */
        <b class="fc"><i>10</i>&nbsp;public abstract class Unit {</b>
        <i>11</i>&nbsp;
        <i>12</i>&nbsp; /**
        <i>13</i>&nbsp; * The square this unit is currently occupying.
        <i>14</i>&nbsp; */
        <i>15</i>&nbsp; private Square square;
        <i>16</i>&nbsp;
        <i>17</i>&nbsp; /**
        <i>18</i>&nbsp; * The direction this unit is facing.
        <i>19</i>&nbsp; */
        <i>20</i>&nbsp; private Direction direction;
        <i>21</i>&nbsp;
        <i>22</i>&nbsp; /**
        <i>23</i>&nbsp; * Creates a unit that is facing east.
        <i>24</i>&nbsp; */
        <b class="nc"><i>25</i>&nbsp; protected Unit() {</b>
        <b class="nc"><i>26</i>&nbsp; this.direction = Direction.EAST;</b>
        <b class="nc"><i>27</i>&nbsp; }</b>
        <i>28</i>&nbsp;
        <i>29</i>&nbsp; /**
        <i>30</i>&nbsp; * Sets this unit to face the new direction.
        <i>31</i>&nbsp; *
        <i>32</i>&nbsp; * @param newDirection The new direction this unit is facing.
        <i>33</i>&nbsp; */
        <i>34</i>&nbsp; public void setDirection(Direction newDirection) {
        <b class="nc"><i>35</i>&nbsp; this.direction = newDirection;</b>
        <b class="nc"><i>36</i>&nbsp; }</b>
        <i>37</i>&nbsp;
        <i>38</i>&nbsp; /**
        <i>39</i>&nbsp; * Returns the current direction this unit is facing.
        <i>40</i>&nbsp; *
        <i>41</i>&nbsp; * @return The current direction this unit is facing.
        <i>42</i>&nbsp; */
        <i>43</i>&nbsp; public Direction getDirection() {
        <b class="nc"><i>44</i>&nbsp; return this.direction;</b>
        <i>45</i>&nbsp; }
        <i>46</i>&nbsp;
        <i>47</i>&nbsp; /**
        <i>48</i>&nbsp; * Returns the square this unit is currently occupying.
        <i>49</i>&nbsp; * Precondition: &lt;code&gt;hasSquare()&lt;/code&gt;.
        <i>50</i>&nbsp; *
        <i>51</i>&nbsp; * @return The square this unit is currently occupying.
        <i>52</i>&nbsp; */
        <i>53</i>&nbsp; public Square getSquare() {
        <b class="nc"><i>54</i>&nbsp; assert invariant();</b>
        <b class="nc"><i>55</i>&nbsp; assert square != null;</b>
        <b class="nc"><i>56</i>&nbsp; return square;</b>
        <i>57</i>&nbsp; }
        <i>58</i>&nbsp;
        <i>59</i>&nbsp; /**
        <i>60</i>&nbsp; * Returns whether this unit is currently on a square.
        <i>61</i>&nbsp; *
        <i>62</i>&nbsp; * @return True iff the unit is occupying a square at the moment.
        <i>63</i>&nbsp; */
        <i>64</i>&nbsp; public boolean hasSquare() {
        <b class="nc"><i>65</i>&nbsp; return square != null;</b>
        <i>66</i>&nbsp; }
        <i>67</i>&nbsp;
        <i>68</i>&nbsp; /**
        <i>69</i>&nbsp; * Occupies the target square iff this unit is allowed to as decided by
        <i>70</i>&nbsp; * {@link Square#isAccessibleTo(Unit)}.
        <i>71</i>&nbsp; *
        <i>72</i>&nbsp; * @param target The square to occupy.
        <i>73</i>&nbsp; */
        <i>74</i>&nbsp; public void occupy(Square target) {
        <b class="nc"><i>75</i>&nbsp; assert target != null;</b>
        <i>76</i>&nbsp;
        <b class="nc"><i>77</i>&nbsp; if (square != null) {</b>
        <b class="nc"><i>78</i>&nbsp; square.remove(this);</b>
        <i>79</i>&nbsp; }
        <b class="nc"><i>80</i>&nbsp; square = target;</b>
        <b class="nc"><i>81</i>&nbsp; target.put(this);</b>
        <b class="nc"><i>82</i>&nbsp; assert invariant();</b>
        <b class="nc"><i>83</i>&nbsp; }</b>
        <i>84</i>&nbsp;
        <i>85</i>&nbsp; /**
        <i>86</i>&nbsp; * Leaves the currently occupying square, thus removing this unit from the board.
        <i>87</i>&nbsp; */
        <i>88</i>&nbsp; public void leaveSquare() {
        <b class="nc"><i>89</i>&nbsp; if (square != null) {</b>
        <b class="nc"><i>90</i>&nbsp; square.remove(this);</b>
        <b class="nc"><i>91</i>&nbsp; square = null;</b>
        <i>92</i>&nbsp; }
        <b class="nc"><i>93</i>&nbsp; assert invariant();</b>
        <b class="nc"><i>94</i>&nbsp; }</b>
        <i>95</i>&nbsp;
        <i>96</i>&nbsp; /**
        <i>97</i>&nbsp; * Tests whether the square this unit is occupying has this unit listed as
        <i>98</i>&nbsp; * one of its occupiers.
        <i>99</i>&nbsp; *
        <i>100</i>&nbsp; * @return &lt;code&gt;true&lt;/code&gt; if the square this unit is occupying has this
        <i>101</i>&nbsp; * unit listed as one of its occupiers, or if this unit is currently
        <i>102</i>&nbsp; * not occupying any square.
        <i>103</i>&nbsp; */
        <i>104</i>&nbsp; protected boolean invariant() {
        <b class="nc"><i>105</i>&nbsp; return square == null || square.getOccupants().contains(this);</b>
        <i>106</i>&nbsp; }
        <i>107</i>&nbsp;
        <i>108</i>&nbsp; /**
        <i>109</i>&nbsp; * Returns the sprite of this unit.
        <i>110</i>&nbsp; *
        <i>111</i>&nbsp; * @return The sprite of this unit.
        <i>112</i>&nbsp; */
        <i>113</i>&nbsp; public abstract Sprite getSprite();
        <i>114</i>&nbsp;
        <i>115</i>&nbsp; /**
        <i>116</i>&nbsp; * A utility method for implementing the ghost AI.
        <i>117</i>&nbsp; *
        <i>118</i>&nbsp; * @param amountToLookAhead the amount of squares to follow this units direction in.
        <i>119</i>&nbsp; * @return The square amountToLookAhead spaces in front of this unit.
        <i>120</i>&nbsp; */
        <i>121</i>&nbsp; public Square squaresAheadOf(int amountToLookAhead) {
        <b class="nc"><i>122</i>&nbsp; Direction targetDirection = this.getDirection();</b>
        <b class="nc"><i>123</i>&nbsp; Square destination = this.getSquare();</b>
        <b class="nc"><i>124</i>&nbsp; for (int i = 0; i &lt; amountToLookAhead; i++) {</b>
        <b class="nc"><i>125</i>&nbsp; destination = destination.getSquareAt(targetDirection);</b>
        <i>126</i>&nbsp; }
        <i>127</i>&nbsp;
        <b class="nc"><i>128</i>&nbsp; return destination;</b>
        <i>129</i>&nbsp; }
        <i>130</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
